﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BestLifePOS_Core.Data.Commands;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Fascade;
using System.Linq;

namespace BestLifePOS_PresentationLayer
{
    public partial class frmReceiptCancel : Form
    {
        public frmReceiptCancel()
        {
            InitializeComponent();
        }

        private void frmReceiptCancel_Load(object sender, EventArgs e)
        {

        }

        private void RecallRecipts()
        {

            //Fill the DataGrid
            Recipt_Detail LvReipts = new Recipt_Detail();
            //LvPR.status = "APPROVED";
            List<Recipt_Detail> LvList = Recipt_DetailDAO.GetReiptsDetailsByReciptId(txtReciptID.Text.ToString());

            DataTable LvTable = new DataTable();
            dgvReciptDetails.DataSource = LvTable;

            LvTable.Columns.Add("R_ID ");
            LvTable.Columns.Add("D_ID ");
            LvTable.Columns.Add("Branch_ID ");
            LvTable.Columns.Add("Date_Create ");
            LvTable.Columns.Add("Pay_Method ");
            LvTable.Columns.Add("Term_ID ");
            LvTable.Columns.Add("Price ");


            foreach (Recipt_Detail LvRecipt in LvList)
            {
                LvTable = (DataTable)dgvReciptDetails.DataSource;

                LvTable.Rows.Add(LvTable.NewRow());

                LvTable.Rows[LvTable.Rows.Count - 1][0] = LvRecipt.R_ID.ToString();
                LvTable.Rows[LvTable.Rows.Count - 1][1] = LvRecipt.Dis_ID.ToString();
                LvTable.Rows[LvTable.Rows.Count - 1][2] = LvRecipt.Branch_Id.ToString();
                LvTable.Rows[LvTable.Rows.Count - 1][3] = LvRecipt.Date_Create.ToString();
                LvTable.Rows[LvTable.Rows.Count - 1][4] = LvRecipt.Pay_Method.ToString();
                LvTable.Rows[LvTable.Rows.Count - 1][5] = LvRecipt.Term_Id.ToString();
                LvTable.Rows[LvTable.Rows.Count - 1][6] = LvRecipt.Price.ToString();



            }
        }

        private void btnRecall_Click(object sender, EventArgs e)
        {
            RecallRecipts();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to cancel the this Recipt!", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                //DataSet ds = new DataSet("rcptdetails");

                //string detailsXML = "";

                //ds.Tables.Add(LvTable2.Copy());
                //detailsXML = ds.GetXml();
                string PcalcelingRcpt = txtReciptID.Text.ToString();
                CancelRecipt(PcalcelingRcpt);
                MessageBox.Show("Recipt Was Succesfuly Canceled");
            }
            else
            {
                MessageBox.Show("Cancelation aborted!");

            }
        }

        private int CancelRecipt(string PcalcelingRcpt)
        {

            string LvCancel = "CANCELED";
            string LvRcpto = PcalcelingRcpt;
            string LvReason = rtxtReason.Text.ToString();
            string LvUser = "1";
           
            if (LvCancel != null)
            {
                return Recipt_DetailDAO.CancelRecipt(LvCancel, LvRcpto, LvReason,LvUser);
            }
            else
            {
                return 0;
            }
        }
    }
}
